﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace modBusTest
{
    struct pair
    {
        public int baseRegister;
        public int range;
    }

    class optimizeRange
    {
    
        bool[] range;
        List<pair> solutionTable = new List<pair>();

        public optimizeRange(int size)
        {   
            range = new bool[size];
            InitializeTable();
        }

        public optimizeRange()
        {
            range = new bool[100001];
            InitializeTable();
        }

        private void InitializeTable()
        {
            for (int i = 0; i < range.Length; i++)
            {
                range[i] = false;
            }
        }

        public void addRegister(ushort register){
            range[register] = true;
        }

        public void solve()
        {
            for (int i = 0; i < range.Length; i++)
            {
                // this will look for parts in the table where value is true
                if (range[i])
                {
                    pair value = new pair(); // this will start tracking if the table is true
                    value.baseRegister = i;
                    value.range = 0;
                    while (range[i]  && value.range < 125)
                    {
                        value.range++;
                        i++;
                    }

                    solutionTable.Add(value);
                }
            }
        }

        public List<pair> getSolution()
        {
            return solutionTable;
        }

        
    }
}
